@extends('agent.mainlayout')
@section('title')
    <div class="title"><span id="test">商品管理></span></div>
@endsection
@section('content')
        <!-- start 商品管理-->
    <div class="list5">
        <div class="header" ><a style="color: white;" href="/center/goods/add/view">商品发布</a></div>
        <table>
            <tr>
                <td>选择</td>
                <td>商品名称</td>
                <td>价格</td>
                <td>库存</td>
                <td>发布时间</td>
                <td>操作</td>
            </tr>
            @if(!empty($rows['data']))
            {{--<tr>--}}
                {{--<td colspan="6" style="float: left;"><input id='abc' type="checkbox"/>全选 <span class="delete" id="delall">删除</span></td>--}}
            {{--</tr>--}}
            @foreach($rows['data'] as $v)
            <tr>
                <td><input name='chk' type="checkbox" value="{{$v['id']}}"/>编号： <span>{{$v['id']}}</span></td>
                <td style="text-align: center">
                    @if(!empty($v['pics'][0]))
                    <img src="{{url($v['pics'][0])}}" alt=""/>
                    @endif
                    <ul>
                        <li>{{$v['name']}}</li>
                        <li>商家货号：{{$v['spu']}}</li>
                        <li>图标</li>
                    </ul>
                </td>
                <td>￥{{$v['price']}}</td>
                <td>{{$v['num']}}</td>
                <td>{{$v['created_at']}}</td>
                <td><a href="{{url('center/goods/edit')}}?id={{$v['id']}}"><span class="green">编辑</span></a><span class="red" id="shanchu"  onclick="delGood({{$v['id']}});">删除</span></td>
            </tr>
            @endforeach

            @else
                <tr>
                <td colspan="6">暂无商品...</td>
                </tr>
            @endif

        </table>
        <div class="del">
            @if($rows['last_page']>1)
            <div class="bot">
                @if($rows['prev_page_url'])
                    <p class="prev"><a href="{{$rows['prev_page_url']}}">上一页</a></p>
                @endif
                <ul>

                    @foreach($rows['pageNoList'] as $v)
                        <li @if($rows['current_page'] ==  $v )class="active_list" @endif ><a href="/center/goods?page={{$v}}">{{$v}}</a></li>
                    @endforeach

                </ul>
                @if($rows['next_page_url'])
                    <p class="next"><a href="{{$rows['next_page_url']}}">下一页</a></p>
                @endif
            </div>
            @endif
        </div>
    </div>
    <!-- end 商品管理-->
    <script>
        {{--<a href="{{url('center/goods/del')}}?id={{$v['id']}}">--}}
            /************ajax删除*************/


            function delGood(id){

                layer.confirm('确认删除该项吗?',{ btn: ['确定','取消']

                },function(){
                    //关闭所有层
                    layer.closeAll();
                    //加载效果
                    layer.load(2, {shade: false});

                    $.ajax({
                        url:'{{url('center/goods/del')}}?id='+id,
                        type:'get',
                        success: function (res) {

                            if(res['status']==1){

                                layer.msg(res.msg, {icon: 6});
                                setTimeout("location.reload()",1500);

                            }else{

                                layer.msg(res.msg, {icon: 5});

                            }

                        }

                    });

                },function(){

//                    layer.msg('你取消了', {
//                        time: 700, //0.7s后自动关闭
//
//                    });
                });
            }




            /************ajax删除*************/

            /********快闪重定向*********/
            var message = "{{Session::get('message')}}";
            $(window).ready(function () {
                if (message) {
                    layer.msg(message, {
                        time: 3000,

                    });
                }
            });
            /********快闪重定向*********/

        /***********全选反选************/
            var mm = true;
            $('#abc').click(function(){

                if(mm==true){

                    $('input[type=checkbox]').prop('checked',true);
                    mm = false;

                }else{

                    $('input[type=checkbox]').prop('checked',false);
                    mm = true;

                 }
            });

            $('#test').click(function(){

               alert( $(':checked').size());

            });
        /***********全选反选************/

        /********批量删除*********/
         $('#delall').click(function () {

//             layer.confirm('确认批量删除?',{btn['确认','取消']},function(){
//
//             },function(){
//
//             });

             var selectItem = new Array();
             $('input[name=chk]:checked').each(function(){

                 selectItem.push($(this).val());  //在数组中追加元素

             });
             //console.log(selectItem);

             if(selectItem.length ==0){

                 layer.msg('请最少选中一个',function(){

                 });

             }else{

                 layer.confirm('确认删除选中项吗?',{btn:['确认','取消']},function(){

                     $.ajax({
                         type:"POST",
                         url:"{{url('center/goods/delall')}}",
                         data:'id='+selectItem.join(','),
                         dataType:'json',
                         success:function(res){

                             if(res['status']==1){

                                 layer.msg(res.msg, {icon: 6});
                                 setTimeout("location.reload()",1500);

                             }else{

                                 layer.msg(res.msg, {icon: 5});

                             }

                         }


                     });

                 },function(){



                 });



             }


         });


        /********批量删除*********/

    </script>
@endsection
